package persistence.repository;

import persistence.PersistenceController;
import persistence.Persistent;
import util.Log;
import util.Subsystem;
import domain.message.Post;

/**
 * repository for posts.
 *
 * @author idan
 */
public class PostRepository extends Repository<Post>
{
	/**
	 * @param persistence persistence provider to store objects.
	 * @pre 'persistence' persists objects of type 'Post'.
	 */
	public PostRepository(final PersistenceController persistence)
	{
		super(persistence) ;
	}

	/**
	 * @param text text in of the new post.
	 * @param authorId id of the author of the new post.
	 * @param threadParentId - the id of the parent thread
	 * @return the newly created post.
	 * @post post exists in the repository.
	 */
	public Post create(final String text, final long authorId, final long threadParentId)
	{
		final Post post = new Post(Persistent.INVALID_ID, text, authorId, threadParentId) ;
		this.put(post) ;
		Log.getLogger(Subsystem.REPOSITORY).finest("post " + post + " created.") ;
		return post ;
	}
}